package com.example.service.impl;

import com.example.mapper.VideosMapper;
import com.example.pojo.Videos;
import com.example.service.VideosService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VideosServiceImpl implements VideosService {
    @Autowired
    private VideosMapper videosMapper;
    @Override
    public List<Videos> findAll() {
        return videosMapper.findAll();
    }

    @Override
    public Videos findById(Integer id) {
        return videosMapper.findById(id);
    }

    @Override
    public void delete(Integer id) {
        videosMapper.delete(id);
    }
    @Override
    public void insert(Videos video) {
        Integer speciesId = videosMapper.findSpeciesIdByName(video.getSpeciesName());
        Integer regionId= videosMapper.findRegionIdByName(video.getRegionName());
        video.setSpeciesId(speciesId);
        video.setRegionId(regionId);
        videosMapper.insert(video);
    }
    @Override
    public void update(Videos video) {
        Integer speciesId = videosMapper.findSpeciesIdByName(video.getSpeciesName());
        Integer regionId= videosMapper.findRegionIdByName(video.getRegionName());
        video.setSpeciesId(speciesId);
        video.setRegionId(regionId);
        videosMapper.update(video);
    }
}
